function CloseWin()
{
  parent.parent.window.close();
}
function EnabledBtns(bEnabled)
{
        parent.frames("Buttons").document.getElementById("btnConfirm").disabled=1-bEnabled;
        parent.frames("Buttons").document.getElementById("btnClose").disabled=0;
}
function SaveInfo()
{
 var index;
 InitItems();
 EnabledBtns(0);
 for (index=0; index<parent.frames.item("AddFunction").document.all.item("moduleItemId").length; index++)
 {
   parent.frames.item("AddFunction").document.all.item("moduleItemId").options[index].selected=true;
   parent.frames.item("AddFunction").document.all.item("Permit").options[index].selected=true;
 }
 parent.frames.item("AddFunction").document.forms.item("theAddForm").submit();
}

function ResetInfo()
{
 var index,FunCode,FunName,ListCount,Len;
  if ( parent.frames.item("AddFunction").document.forms.item("AddFunForm").SelectedList.length>0)
  {
   Count= parent.frames.item("AddFunction").document.forms.item("AddFunForm").SelectedList.length;
   for (index=Count-1;index>=0;index--)
   {
    FunCpde=parent.frames.item("AddFunction").document.forms.item("AddFunForm").SelectedList.options(index).value;
    FunName=parent.frames.item("AddFunction").document.forms.item("AddFunForm").SelectedList.options(index).text;
    parent.frames.item("AddFunction").document.forms.item("AddFunForm").SelectedList.remove(index);
    Len=parent.frames.item("FunctionList").FunctionList.length;
    parent.frames.item("FunctionList").FunctionList.length=Len+1;
    parent.frames.item("FunctionList").FunctionList.options(Len).text=FunName;
    parent.frames.item("FunctionList").FunctionList.options(Len).value=FunCode;
  }
 }
}

function InitItems()
{
 var optionLen,selObj;
 parent.frames("AddFunction").document.all.item("Permit").length=0;
 parent.frames("AddFunction").document.all.item("moduleItemId").length=0;
 selObj=parent.frames("AddFunction").document.all.tags("Select");
 if (selObj!=null)
 {
  for (i=0;i<selObj.length-2;i++)
   {
	 optionLen=parent.frames("AddFunction").document.all.item("Permit").length;
	 parent.frames("AddFunction").document.all.item("Permit").length=optionLen+1;
	 parent.frames("AddFunction").document.all.item("moduleItemId").length=optionLen+1;

         parent.frames("AddFunction").document.all.item("Permit").options(optionLen).value=selObj[i].value;
         parent.frames("AddFunction").document.all.item("Permit").options(optionLen).text=selObj[i].value;

        parent.frames("AddFunction").document.all.item("moduleItemId").options(optionLen).value=parent.frames("AddFunction").document.all.item("Tb").rows(i+1).id;
        parent.frames("AddFunction").document.all.item("moduleItemId").options(optionLen).text=parent.frames("AddFunction").document.all.item("Tb").rows(i+1).id;
    }
 }
}
